package com.yc.ssm.biz.impl;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yc.ssm.bean.ProductInfo;
import com.yc.ssm.biz.IProductInfoBiz;
import com.yc.ssm.mapper.IProductInfoMapper;
import com.yc.ssm.util.StringUtil;
@Service
public class ProductInfoBizImpl implements IProductInfoBiz {
	@Autowired
	private IProductInfoMapper productMapper;
	@Override
	public int add(ProductInfo pf) {
		if(StringUtil.checkNull(pf.getGname(),pf.getPrice(),pf.getTno(),pf.getPics())) {
			return -1;
		}
		return productMapper.add(pf);
	}

	@Override
	public List<ProductInfo> finds(Map<String,Object> map) {
		return productMapper.finds(StringUtil.findByPageUtil(map));
	}

	@Override
	public Map<String, Object> findByFirst(Map<String,Object> map) {
		List<ProductInfo> list = productMapper.finds(StringUtil.findByPageUtil(map));
		//list.isEmpty() 里面没有数据
		if(list == null || list.isEmpty()) {
			return Collections.emptyMap();
		}
		Map<String,Object> resutlt = new HashMap<String,Object>();
		resutlt.put("total", productMapper.total());
		resutlt.put("rows", list);
		return resutlt;
	}


}
